package org.hrds.rdupm.config;

import org.hzero.core.message.MessageAccessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

@Configuration
public class LocalValidatorConfig {

    @Bean
    public LocalValidatorFactoryBean getValidator() {
        LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
        ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource = new ReloadableResourceBundleMessageSource();
        reloadableResourceBundleMessageSource.addBasenames(MessageAccessor.getBasenames());
        reloadableResourceBundleMessageSource.addBasenames("classpath:messages/messages");
        reloadableResourceBundleMessageSource.setDefaultEncoding("UTF-8");
        bean.setValidationMessageSource(reloadableResourceBundleMessageSource);
        return bean;
    }
}
